package com.shyroke.daydayzhuanweb.controller.app;


import com.shyroke.daydayzhuanapi.dto.AppAboutDto;
import com.shyroke.daydayzhuanapi.dto.AppApiModel;
import com.shyroke.daydayzhuanapi.dto.ProjectDto;
import com.shyroke.daydayzhuanapi.entity.VersionEntity;
import com.shyroke.daydayzhuandao.respository.VersionRepository;
import com.shyroke.daydayzhuansvc.manager.ProjectManager;
import com.shyroke.daydayzhuansvc.service.IProjectService;
import com.shyroke.daydayzhuansvc.service.impl.ProjectApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 用于安卓请求controller
 */
@RestController
@RequestMapping(value = "api")
public class NewAPIController {

    @Autowired
    private ProjectApiService projectApiService;
    @Autowired
    private VersionRepository versionRepository;
    @Autowired
    private ProjectManager projectManager;

    /**
     * 获取置顶项目
     * @return
     */
    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public AppApiModel getIndex(){
        return projectApiService.getIndexData();
    }

    /**
     * 获取最新项目
     * @return
     */
    @RequestMapping(value = "/article/page",method = RequestMethod.GET)
    public AppApiModel getNewsProject(Integer page){
        return projectApiService.newsArticle(page,  10);
    }


    @GetMapping("version")
    public AppApiModel getVersion() {
        VersionEntity e = versionRepository.findById(1).orElse(null);
        if(e == null) {
            return AppApiModel.builder().Code(500).Msg("版本号为空").build();
        }
        return AppApiModel.builder().Data(e.getVersion()).build();
    }

    @GetMapping("shouma")
    public AppApiModel shouMa(Integer page) {
        return projectApiService.getArticleByType(page, 2,  10, null);
    }

    @GetMapping("yangmao")
    public AppApiModel yangmao(Integer page) {
        return projectApiService.getArticleByType(page, 1, 30,  18);
    }
}
